package com.eduhzy.ttw.work.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.http.CommonApi;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.contract.WorkStatusContract;
import com.eduhzy.ttw.work.mvp.model.WorkStatusModel;
import com.eduhzy.ttw.work.mvp.model.entity.WorkClassData;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-3 16:43:36
 */
@Module
public class WorkStatusModule {
    private WorkStatusContract.View view;

    /**
     * 构建WorkStatusModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public WorkStatusModule(WorkStatusContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    WorkStatusContract.View provideWorkStatusView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    WorkStatusContract.Model provideWorkStatusModel(WorkStatusModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<WorkClassData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<WorkClassData, AutoBaseViewHolder> providerAdapter(List<WorkClassData> lists) {
        return new BaseQuickAdapter<WorkClassData, AutoBaseViewHolder>(R.layout.work_rv_item_work_status, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, WorkClassData item) {
                Glide.with(mContext)
                        .load(CommonApi.APP_AVATAR + item.getUserId())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_name, item.getUserRealName());
                helper.setGone(R.id.tv_status, item.getScore() > 0);
                if (item.getLevel() > 0) {
                    helper.setText(R.id.tv_status, Constants.LEVEL_TXT[item.getScore() - 1]);
                }
            }
        };
    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new LinearLayoutManager(view.getActivity());
    }

}